package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.PmsBrandMapper;
import com.mall.domain.PmsBrand;
import com.mall.domain.SmsCoupon;
import com.mall.interface1.api.PmsBrandApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsBrandApiImpl implements PmsBrandApi {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    //获取全部品牌列表
    @Override
    public List<PmsBrand> findAllBrand() {
        return pmsBrandMapper.selectList(null);
    }

    //添加品牌
    @Override
    public Integer save(PmsBrand pmsBrand) {
        return pmsBrandMapper.insert(pmsBrand);
    }

    //根据条件分页查询出品牌名称列表
    @Override
    public List<PmsBrand> list(Integer pageNum, Integer pageSize, String keyword) {
        Page<PmsBrand> psPage = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(keyword != null, PmsBrand::getName, keyword)
                .or().like(keyword != null, PmsBrand::getFirstLetter, keyword);
        Page<PmsBrand> page = pmsBrandMapper.selectPage(psPage, queryWrapper);
        return page.getRecords();
    }

    //查询符合条件的总记录条数
    @Override
    public Integer count(Integer pageNum, Integer pageSize, String keyword) {
        LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(keyword != null, PmsBrand::getName, keyword)
                .or().like(keyword != null, PmsBrand::getFirstLetter, keyword);
        return pmsBrandMapper.selectCount(queryWrapper);
    }

    //批量删除品牌
    @Override
    public Integer deleteByIds(List<Long> list) {
        return pmsBrandMapper.deleteBatchIds(list);
    }

    //更新品牌
    @Override
    public Integer updateBrand(PmsBrand pmsBrand) {
        return pmsBrandMapper.updateById(pmsBrand);
    }

    //根据编号查询品牌信息
    @Override
    public PmsBrand findById(Long id) {
        return pmsBrandMapper.selectById(id);
    }
}
